class Checkout < ActiveRecord::Base
  attr_accessible :address, :email, :is_gift, :name, :pay_type, :shipping_type, :status
    
  validates :name, :address, :email, presence: true, if: :on_order_person_step?
  validates_format_of :email, :with => /^(|(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6})$/i, if: :on_order_person_step?
      
  validates :pay_type, inclusion: Order::PAYMENT_TYPES, if: :on_order_options_step?
  validates :shipping_type, inclusion: Order::SHIPPING_TYPES, if: :on_order_options_step?
  
  def on_order_person_step?
    status == ('order_person')
  end
  
  def on_order_options_step?
    status == ('order_options')
  end
  
  def on_order_summary_step?
    status == ('order_summary')
  end
end